import { h } from 'vue'
import { Icon } from '@iconify/vue'
import { NIcon } from 'naive-ui'
import SvgIcon from '@/components/SvgIcon.vue'

export function renderIcon(icon, props = { size: 12 }) {
    return () => h(NIcon, props, { default: () => h(Icon, { icon }) })
}

export function renderCustomIcon(icon, props = { size: 12 }) {
    return () => h(NIcon, props, { default: () => h(SvgIcon, { icon }) })
}

export function getIcon(meta) {
    if (meta?.customIcon) return renderCustomIcon(meta.customIcon, { size: 18 });
    if (meta?.icon) return renderIcon(meta.icon, { size: 18 });
    return null;
}